<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <title>原生文件上传</title>
</head>

<body>
  <input type="file">
  <script>
    var ele = document.querySelector('input');
    ele.onchange = function (e) {
      console.log('e...', e);
      let files = e.target.files;
      // 创建一个formData
      let form = new FormData();
      for (let i = 0, len = files.length; i < len; i++) {
        console.log(files[i].name);
        form.append(files[i].name, files[i]);
      }
      console.log('form...', form);

      axios({
        method: 'post',
        url: 'http://123.206.55.50:11000/upload',
        data: form
      }).then(body => {
        console.log('body...', body);
      }).catch(e => {
        console.log('e..', e);
      })
    }
    // var ele = document.querySelector('input');
    //   ele.onchange = function(e){
    //     let files = e.target.files;
    //     var reader = new FileReader();
    //     reader.onload = function(){
    //         console.log('result...', this.result);
    //         axios({
    //             method: 'post',
    //             url: 'http://123.206.55.50:11000/upload_base64',
    //             data: {base64: this.result}
    //         }).then(body=>{
    //             console.log('body...', body);
    //         }).catch(e=>{
    //             console.log('e..', e);
    //         })
    //     }
    //     reader.readAsDataURL(files[0]);
    // }
  </script>
</body>

</html>